import React, { Component } from 'react';
import $ from "jquery";
import {BrowserRouter as Router, Route,Link} from 'react-router-dom'; 
// import {HashRouter as Router, Route, Link} from 'react-router-dom';
// 
// import Detail from "./detail.js";
import {connect} from "react-redux";

class ContentNows extends Component {
  componentDidMount(){
      var that = this;
      $.get("http://localhost:8080/now_playing?page=1&count=7",function(res){
          var data = JSON.parse(res).data.films;
          console.log(data);
          that.props.getNowPlayData(data);
      });
 
  }
  render() {
    return (
              <ul className="content" ref="content">
                  {
                    this.props.getData.map(function(item,index){
                        return(
                            <li key={index}>
                                <Link to={"/detail/"+item.id}>
                                  <img src={item.poster.origin} alt="图片显示异常，请刷新后再试"/>
                                  <div className="content_right">
                                      <h3><span className="name">{item.name}</span><i className="iconfont">&#xe649;</i><span className="grade">{item.grade}</span></h3>
                                      <p className="detail1">{item.intro}</p>
                                      <p className="detail2"><span className="shop_num">{item.cinemaCount}</span>家影院上映<span className="person_num">{item.watchCount}</span>人购票</p>
                                  </div>
                                </Link>
                          </li>
                        )
                    })
                  }
              </ul>

      
    );
  }
}

var ContentNow = connect(
  function(state, ownProps) {
    return {
          getData:state.getNowPlayData1
    }
  },
  function(dispatch, ownProps) {
   return {
        getNowPlayData:function(data){
            dispatch({
                type:"GETNOWPLAYDATA",
                data:data
            })
        },
        loadPage:function(id){
            dispatch({
              type:"lOADPAGE",
              idNum:id
            })
        }
    }
  }
)(ContentNows);

export default ContentNow;
